<?php
$con = mysqli_connect('localhost', 'root', 'root');
if (!$con) {
    die('连接失败' . mysqli_connect_error());
}
mysqli_select_db($con, 'blog');
mysqli_set_charset($con, 'utf8');
$sql = "select * from blog_type order by type_id desc";
$result = mysqli_query($con, $sql);
if (!$result) {
    //返回的时最近一次的错误
    echo '查询失败' . mysqli_error($con);
} else {
    $type_list = [];
    while ($row = mysqli_fetch_assoc($result)) {
        $type_list[] = $row;
    }
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>博客类别展示</title>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <a href="index.html">返回导航</a>
    <a href="blogtype_add.html">添加类别</a>
    <table class="table">
        <tr>
            <th>类别编号</th>
            <th>类别名称</th>
            <th>修改</th>
        </tr>
        <?php
        foreach ($type_list as $key => $value) { ?>
            <tr>
                <td><?php echo $value['type_id'] ?></td>
                <td><?php echo $value['type_name'] ?></td>
                <td><a class="btn btn-primary" href="blogtype_edite.php?id=<?php echo $value['type_id'] ?>">编辑</a> </td>
            </tr>
        <?php }
        ?>
    </table>
</div>
</body>
</html>
